2  Before you begin

All course modules will start with a Before you begin section. In these sections, you will download data and scripts required to complete the module, install any required packages, and take other necessary steps before diving into the material. In this lesson, you will learn:

Important! Before starting this lesson, be sure that you have followed the steps provided in Lesson 1.1: Installing R and RStudio to install the most current version of R and RStudio. This lesson also assumes that you are familiar with the concepts and terminology covered in Lesson 1.3: The RStudio IDE.

2.1 Set your global options

RStudio’s global options define the behavior and layout of the RStudio IDE every time you open the program. Here, we will modify your global options to ensure that they are set to maximize your success in this course (and beyond).

Please follow the steps in the video below to set up your global options:

2.2 Set up your session

An R Studio session represents the time spent and operations conducted since opening R.

2.2.1 Open an RStudio project

A session is initiated by opening a project in RStudio. A project is a folder that contains a collection of files (e.g., scripts, data, output) and sub-folders. The parent folder is designated as a project if it includes a .Rproj file. All content for this course will be stored in a project and all code will be executed from within this project.

We can open our project in one of four ways:

The project menu ()

Note: If you use this method, you can open a recent project by simply clicking on the name from the list of options at the bottom of the dropdown menu.

  1. Open RStudio
  2. Click the blue square in the upper right of the window
  3. Navigate to “Open Project …”
  4. Navigate to your project in the window that opens
  5. Double-click on the .Rproj file.

The file menu

  1. Open RStudio
  2. In the top menu bar, click “File”
  3. Navigate to “Open Project …”
  4. Navigate to your project in the window that opens
  5. Double-click on the .Rproj file.

Using a keyboard shortcut

  1. Open RStudio
  2. Hit the keyboard shortcut Control + O (Windows) or Command + O (Mac)
  3. Navigate to your project in the window that opens
  4. Double-click on the .Rproj file.
  5. Hit enter on the following pop-up menu.

Windows Explorer () or Finder ()

  1. Open your system’s file explorer (e.g. “Finder” on Macs)
  2. Navigate to your project in the window that opens
  3. Double-click on the .Rproj file.

Always work within a project!

Working in an RStudio project offers lots of advantages. These include (but are not limited to):

  • Your project folder is the root directory of files read in by R. In other words, you read in files relative to their location within the project folder.
  • Projects ensure that your data and scripts are stored in one, easy-to-find, space.
  • Through sharing projects, rather than individual files, it is easy to generate reproducible scripts.
  • Projects provide you with the opportunity to use different versions of packages for various applications.

We will explore these advantages and more in coming lessons!

2.2.2 Housekeeping steps

At the beginning of each session, I like to do a series of what I call “housekeeping steps”. These include clearing any open scripts, your global environment, and your code history. Doing so helps you better organize your workflow and ensures that you can make the most out of RStudio’s tools for managing your code and data during a session.

I strongly recommend following the steps below at the start of each session:

  1. If there are any script files open in your source pane. Close them. Note: If any of your script titles are blue, you might want to save them prior to closing!

  1. In the Environment tab of your workspace pane, ensure that your Global Environment is empty. If it is not, click the broom to remove all objects.

  1. In the History tab of your workspace pane, ensure that your history is empty. If it is not, click the broom to remove your history.

By completing the steps above, your current session will be dedicated, in its entirety, to the task at hand!